<?php
	include "layout.php";
	
	head("Display Planet");
?>
<?php 
	if (!isset($_GET["id"])) {
		header("Location: planets.php");
	}
	$id = $_GET["id"];
	$planetq = mysql_query("SELECT * FROM planets where id={$id}");
	$planet = mysql_fetch_array($planetq);
	$name = $planet["name"];
	$size = $planet["size"];
	
	echo "<h1>{$name}</h1>";
	
	echo "<table border=1 id='planet'>";
	for ($y = 0; $y < $size; $y++) {
		echo "<tr>";
		for($x = 0; $x < $size; $x++) {
			$depositq = mysql_query("SELECT * FROM deposits WHERE planet={$id} and x={$x} and y={$y}");
			$deposit = mysql_fetch_array($depositq);
			$deposits = mysql_num_rows($depositq);
			if ($deposits == 0) {
				echo "<td title='{$x},{$y}'></td>";
			}
			else {
				$terrainq = mysql_query("SELECT * FROM terrain where id = {$deposit["terrain"]}");
				$terrain = mysql_fetch_array($terrainq);
				echo "<td title='{$x},{$y} - {$terrain["name"]}' style='background: url(images/terrain{$deposit["terrain"]}.gif); background-size: 50px 50px; background-repeat:no-repeat;'><img src='images/deposit{$deposit["rmtype"]}.gif' width='50px' height='50px' /></td>";
			}
		}
		echo "</tr>";
	}
	echo "</table>";
?>
<?php 
	foot();
?>